﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace prog_tech_5
{
    public interface ILogger
    {
        void Log(string message);
    }

    public class ConsoleLogger : ILogger
    {
        public void Log(string message)
        {
            Console.WriteLine(message);
        }
    }

    public class FileLogger : ILogger
    {
        private StreamWriter _log_file;

        public FileLogger(string path)
        {
            _log_file = new StreamWriter(path);
        }

        ~FileLogger()
        {
            // _log_file.Close();
        }

        public void Log(string message)
        {
            _log_file.WriteLine(message);
            _log_file.Flush();
        }
    }

    public interface ILoggerFactory
    {
        ILogger CreateLogger();
        ILogger CreateLogger(string path);
    }

    public class FileLoggerFactory : ILoggerFactory
    {
        public ILogger CreateLogger()
        {
            throw new Exception();
        }
        public ILogger CreateLogger(string path)
        {
            var logger = new FileLogger(path);
            logger.Log("File logger init");
            return logger;
        }
    }

    public class ConsoleLoggerFactory : ILoggerFactory
    {
        public ILogger CreateLogger()
        {
            var logger = new ConsoleLogger();
            logger.Log("Console logger init");
            return logger;
        }
        public ILogger CreateLogger(string path)
        {
            var logger = new ConsoleLogger();
            logger.Log("Console logger init");
            return logger;
        }
    }
}
